/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * StatisticsReport.java
 *
 * Created on May 15, 2012, 2:30:54 PM
 */
package GUI;
import system_interface.*;
import java.awt.Dimension;
import java.util.*;
/**
 *
 * @author jmille80
 */
public class StatisticsReport extends Report {
    private ArrayList<Statistic> Statistics = new ArrayList<Statistic>();
    /** Creates new form StatisticsReport */
    public StatisticsReport(SystemInterface si, Dimension d) {
        super(si,d);
        initComponents();
        CreateStatistics();
    }

    private void CreateStatistics() {
        Statistics.add(new Statistic("Total Customers", new StatisticGetter() {

            @Override
            public String GetStatistic() {
                return si.getTotalNumCustomers();
            }
        }
        ));
        Statistics.add(new Statistic("Average Wait for Service", new StatisticGetter() {

            @Override
            public String GetStatistic() {
                return si.getAverageCustomerWaitingTime();
            }
        }
        ));
        Statistics.add(new Statistic("Average Prep Time", new StatisticGetter() {

            @Override
            public String GetStatistic() {
                return si.getAveragePrepTime();
            }
        }
        ));
        Statistics.add(new Statistic("Average Food Wait", new StatisticGetter() {

            @Override
            public String GetStatistic() {
                return si.getAverageCookDeliveryTime();
            }
        }
        ));
    }

        @Override
    public void Update() {
        int row = 0;
        for(Statistic s: Statistics) {
            statTable.getModel().setValueAt(s.getName(), row, 0);
            statTable.getModel().setValueAt(s.getValue(), row, 1);
            row++;
        }
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        statTable = new javax.swing.JTable();

        statTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null},
                {null, null},
                {null, null}
            },
            new String [] {
                "Statistic", "Value"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.Object.class
            };
            boolean[] canEdit = new boolean [] {
                false, true
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(statTable);
        statTable.getColumnModel().getColumn(0).setResizable(false);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 485, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 451, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable statTable;
    // End of variables declaration//GEN-END:variables


    
    private class Statistic {
        private String Name;
        private StatisticGetter StatGetter;
        public Statistic(String Name, StatisticGetter sg) {
            this.Name = Name; this.StatGetter = sg;
        }

        public String getName() {return Name;}
        public String getValue() {return StatGetter.GetStatistic();}
        
        
    }
    
    private interface StatisticGetter {
        public String GetStatistic();
    }
    
}

